﻿using Mengsk.ProxyDelivery.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mengsk.ProxyDelivery.Print.Domain.PrintDataFormatters
{
    class PrintDataFormatterOrder_DeliveryNumberText : PrintDataFormatter
    {
        public override PrintTemplateItemTypes AcceptType
        {
            get { return PrintTemplateItemTypes.ORDER_DELIVERYNUMBERTEXT; }
        }

        public override object Format(PrintTemplate template, PrintTemplateItem item, Order order)
        {
            if (string.IsNullOrWhiteSpace(order.DeliveryNumber))
            {
                throw new Exception("订单:" + order.Id + "，快递单号为空");
            }

            string s = "";
            string number = order.DeliveryNumber;
            for (int i = 0; i < number.Length; i+=4)
            {
                if (number.Length - i >= 4)
                {
                    s += number.Substring(i, 4) + " ";
                }
                else
                {
                    s += number.Substring(i, number.Length - i);
                }
            }
            return s;
        }
    }
}
